<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
 <TITLE>SDCC Compiler User Guide: Cyclomatic Complexity</TITLE>
 <LINK HREF="SDCCUdoc-25.html" REL=next>
 <LINK HREF="SDCCUdoc-23.html" REL=previous>
 <LINK HREF="SDCCUdoc.html#toc24" REL=contents>
</HEAD>
<BODY>
<A HREF="SDCCUdoc-25.html">Next</A>
<A HREF="SDCCUdoc-23.html">Previous</A>
<A HREF="SDCCUdoc.html#toc24">Contents</A>
<HR>
<H2><A NAME="Cyclomatic"></A> <A NAME="s24">24. Cyclomatic Complexity</A> </H2>

<P>Cyclomatic complexity of a function is defined as the number of independent
paths the program can take during execution of the function. This is an important
number since it defines the number test cases you have to generate to validate
the function . The accepted industry standard for complexity number is 10,
if the cyclomatic complexity reported by SDCC exceeds 10 you should think about
simplification of the function logic.
<P>Note that the complexity level is not related to the number of lines of
code in a function. Large functions can have low complexity, and small functions
can have large complexity levels. SDCC uses the following formula to compute
the complexity.
<P>
<PRE>
complexity = (number of edges in control flow graph) - 
             (number
 of nodes in control flow graph) + 2;
 
</PRE>
<P>Having said that the industry standard is 10, you should be aware that
in some cases it may unavoidable to have a complexity level of less than 10.
For example if you have switch statement with more than 10 case labels, each
case label adds one to the complexity level. The complexity level is by no
means an absolute measure of the algorithmic complexity of the function, it
does however provide a good starting point for which functions you might look
at for further optimization.
<HR>
<A HREF="SDCCUdoc-25.html">Next</A>
<A HREF="SDCCUdoc-23.html">Previous</A>
<A HREF="SDCCUdoc.html#toc24">Contents</A>
</BODY>
</HTML>
